package cn.wiseda.finance.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import cn.wiseda.finance.dao.util.JdbcBasicDao;
import cn.wiseda.finance.entity.Organization;

@Component
public class OrganDao extends JdbcBasicDao {
	
	private static final Logger log = LoggerFactory.getLogger("OrganDao");

	public boolean saveOrgan(Organization organ) {
		String sql = "INSERT INTO t_organ (name,address,artificial_person) VALUES(?,?,?)";
		int insert = update(sql, organ.getName(), organ.getAddress(), organ.getArtificialPerson());
		return insert > 0 ? true : false;
	}

	public List<Organization> getOrganList() {
		String sql = "select * from t_organ";
		List<Organization> list = queryForBeans(sql, Organization.class);
		return list;
	}

	public Organization getOrgan(int id) {
		log.info("查询组织机构，代码：" + id);
		String sql = "select * from t_organ where id = ?";
		Organization organization = queryForBean(sql, Organization.class, id);
		return organization;
	}

	public boolean modifyOrgan(Organization organ) {
		log.info("修改组织机构信息");
		String sql = "UPDATE t_organ SET name=?,address=?,artificial_person=? WHERE id=?";
		int update = update(sql, organ.getName(), organ.getAddress(), organ.getArtificialPerson(),
				organ.getId());
		return update > 0 ? true : false;
	}
}
